import { AxiosRequestConfig } from 'axios'
import { createInstance } from './audit'

const instance = createInstance(process.env.API_URL || 'http://localhost:28082/api')

export async function createSnapshot(): Promise<string> {
  const config: AxiosRequestConfig<any> = {
    url: '/span-snapshots',
    method: 'POST',
    data: {
      fieldConditions: [],
      statusConditions: [{ status: 1, minDelay: 1000 }, { status: 2 }, { status: 3 }],
      timeCondition: {
        timeType: 1,
        recentSeconds: 3600 * 3
      },
      for: 1
    }
  }

  const data = await instance.request(config).then((res) => res.data.data)
  return data as string
}
